package com.share.lottery.activity.caiborecommond;

import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

import com.share.lottery.R;
import com.share.lottery.activity.JcMainActivtiy;
import com.share.lottery.adapter.BuyCaiboAdapter;
import com.share.lottery.base.BaseActivity;
import com.share.lottery.base.Constants;
import com.share.lottery.model.OrderBean;
import com.share.lottery.model.OrderServiceBean;

/**
 * @author py
 *购买彩宝推荐
 */
public class BuyCaibotjActivity extends BaseActivity {
	private ListView list;
	private BuyCaiboAdapter adapter;
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.buy_caibao_main);
		showProgreessDialog();
		init();
	}

	public void findView() {
		list = (ListView) findViewById(R.id.audio_list);
		
	}

	
	public void getData() {
		//CaiboRmdController.getInstance().caibaoRmdOrder(handler, "0");//loginid

	}


	private TextView titleTv;
	public void initTitle() {
		
		ImageButton titleLeftImg = (ImageButton) findViewById(R.id.title_left_img);
		ImageButton titleRightImg = (ImageButton) findViewById(R.id.title_right_img);
		titleTv = (TextView) findViewById(R.id.title_tv_center);

		titleLeftImg.setImageResource(R.drawable.back);
		titleTv.setText("彩宝推荐服务订购");
		titleRightImg.setVisibility(View.GONE);
		titleRightImg.setImageResource(R.drawable.home_caibaochat);
		titleRightImg.setOnClickListener(new OnClickListener() {
			
		
			public void onClick(View arg0) {
				Intent intent = new Intent();
				intent.setClass(getApplicationContext(), JcMainActivtiy.class);
				startActivity(intent);
			}
		});
		titleLeftImg.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View view) {
				finish();

			}
		});
	}


	public void setData() {
		if (adapter == null) {
			adapter = new BuyCaiboAdapter(this);
		}
		list.setAdapter(adapter);
	}


	public void setonCliker() {
		

	}
	
	private void doMessage(Message msg) {
		switch (msg.arg1) {
		case Constants.HTTP_OK_LASTID://返回laseid
			
			
			break;
		
		case Constants.HTTP_OK://请求成功
			OrderBean orderBean = (OrderBean) msg.obj;
			if (orderBean != null) {
				List<OrderServiceBean> datas = orderBean.getServices();
				adapter.addDatas(datas);
			}
			break;
		case Constants.HTTP_ERROR://请求错误
			String serror = (String) msg.obj;
			showShortToast(serror);
			break;
		case Constants.HTTP_ERROR_PASER://数据解析错误
			showShortToast("数据解析错误");
			break;
		case Constants.HTTP_ERROR_NET://网络错误

		default:
			break;
		}

	}

	Handler handler = new Handler(){
		public void handleMessage(Message msg) {
			dismissProgressDialog();
		
			switch (msg.what) {
			case Constants.CAIBO_RMD_ORDER:
				doMessage(msg);
				break;
				
			default:
				break;
			}

		}


	};

}
